//会员
let defaultState={
    uid: localStorage['uid'] ? localStorage['uid'] : "",
    nickname: localStorage['nickname'] ? localStorage['nickname']: "",
    authToken: localStorage['authToken'] ? localStorage['authToken'] : '',
    isLogin: localStorage['isLogin'] ? Boolean(localStorage['isLogin']) : false
};

function userReducer(state=defaultState,action){
    switch (action.type){
        case "login": //会员登录
            localStorage['nickname'] = action.data.nickname;
            localStorage['authToken'] = action.data.authToken;
            localStorage['uid'] = action.data.uid;
            localStorage['isLogin'] = action.data.isLogin;
            return { ...state, ...action.data };
        case "outLogin": //安全退出
            localStorage.clear(); 
            sessionStorage.removeItem('aid');
            return Object.assign({}, state, { nickname: "", isLogin: false, uid: '', authToken: '' });
        default:
            return state;
    }
}

export default userReducer;